

# Appendix table: Testing the simulated instrument -----------------------------
tmp = feols(
  price_mrg ~
  sw(mrg_sim_iv_10_14_lag2, mrg_sim_iv_11_13_lag2) + I(bill_hdd/days) | 
  hh_id + city_ym,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
tmp[[1]]
tmp[[2]]

# Lags: City FEs; Marginal price -----------------------------------------------
# Lead 1
est_lead1 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_mrg_lead1) ~ spot_price_1week_lead1 + spot_price_1week_lead1:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 0 (contemporaneous)
est_lag0 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_mrg) ~ spot_price_1week + spot_price_1week:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 1
est_lag1 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_mrg_lag1) ~ spot_price_1week_lag1 + spot_price_1week_lag1:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 2
est_lag2 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_mrg_lag2) ~ spot_price_1week_lag2 + spot_price_1week_lag2:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 3
est_lag3 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_mrg_lag3) ~ spot_price_1week_lag3 + spot_price_1week_lag3:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Save
qs::qsave(
  x = list(est_lead1, est_lag0, est_lag1, est_lag2, est_lag3),
  file = file.path(dir_project, 'DataR', 'Results', 'Results20220818', 'lags-city-mrg.qs')
)
# Clean up
rm(est_lead1, est_lag0, est_lag1, est_lag2, est_lag3)
gc()


# Lags: City FEs; Average price ------------------------------------------------
# Lead 1
est_lead1 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_avg_lead1) ~ spot_price_1week_lead1 + spot_price_1week_lead1:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 0 (contemporaneous)
est_lag0 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_avg) ~ spot_price_1week + spot_price_1week:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 1
est_lag1 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_avg_lag1) ~ spot_price_1week_lag1 + spot_price_1week_lag1:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 2
est_lag2 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_avg_lag2) ~ spot_price_1week_lag2 + spot_price_1week_lag2:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 3
est_lag3 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_avg_lag3) ~ spot_price_1week_lag3 + spot_price_1week_lag3:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Save
qs::qsave(
  x = list(est_lead1, est_lag0, est_lag1, est_lag2, est_lag3),
  file = file.path(dir_project, 'DataR', 'Results', 'Results20220818', 'lags-city-avg.qs')
)
# Clean up
rm(est_lead1, est_lag0, est_lag1, est_lag2, est_lag3)
gc()


# Lags: City FEs; Average marginal price ---------------------------------------
# Lead 1
est_lead1 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_avg_mrg_lead1) ~ spot_price_1week_lead1 + spot_price_1week_lead1:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 0 (contemporaneous)
est_lag0 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_avg_mrg) ~ spot_price_1week + spot_price_1week:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 1
est_lag1 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_avg_mrg_lag1) ~ spot_price_1week_lag1 + spot_price_1week_lag1:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 2
est_lag2 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_avg_mrg_lag2) ~ spot_price_1week_lag2 + spot_price_1week_lag2:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 3
est_lag3 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_avg_mrg_lag3) ~ spot_price_1week_lag3 + spot_price_1week_lag3:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Save
qs::qsave(
  x = list(est_lead1, est_lag0, est_lag1, est_lag2, est_lag3),
  file = file.path(dir_project, 'DataR', 'Results', 'Results20220818', 'lags-city-avg-mrg.qs')
)
# Clean up
rm(est_lead1, est_lag0, est_lag1, est_lag2, est_lag3)
gc()


# Lags: City FEs; Baseline price -----------------------------------------------
# Lead 1
est_lead1 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_base_lead1) ~ spot_price_1week_lead1 + spot_price_1week_lead1:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 0 (contemporaneous)
est_lag0 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_base) ~ spot_price_1week + spot_price_1week:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 1
est_lag1 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_base_lag1) ~ spot_price_1week_lag1 + spot_price_1week_lag1:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 2
est_lag2 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_base_lag2) ~ spot_price_1week_lag2 + spot_price_1week_lag2:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 3
est_lag3 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(price_base_lag3) ~ spot_price_1week_lag3 + spot_price_1week_lag3:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Save
qs::qsave(
  x = list(est_lead1, est_lag0, est_lag1, est_lag2, est_lag3),
  file = file.path(dir_project, 'DataR', 'Results', 'Results20220818', 'lags-city-base.qs')
)
# Clean up
rm(est_lead1, est_lag0, est_lag1, est_lag2, est_lag3)
gc()


# Lags: City FEs; Simulated marginal price -------------------------------------
# Lead 1
est_lead1 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(mrg_sim_iv_10_14_lead1) ~ spot_price_1week_lead1 + spot_price_1week_lead1:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 0 (contemporaneous)
est_lag0 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(mrg_sim_iv_10_14) ~ spot_price_1week + spot_price_1week:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 1
est_lag1 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(mrg_sim_iv_10_14_lag1) ~ spot_price_1week_lag1 + spot_price_1week_lag1:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 2
est_lag2 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(mrg_sim_iv_10_14_lag2) ~ spot_price_1week_lag2 + spot_price_1week_lag2:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Lag 3
est_lag3 = feols(
  log(thm_day) ~
    I(bill_hdd/days) | 
    hh_id + city_ym |
    log(mrg_sim_iv_10_14_lag3) ~ spot_price_1week_lag3 + spot_price_1week_lag3:utility,
  cluster = ~hh_id + price_cluster,
  data = sub_dt,
  mem.clean = TRUE,
  lean = FALSE
)
# Save
qs::qsave(
  x = list(est_lead1, est_lag0, est_lag1, est_lag2, est_lag3),
  file = file.path(dir_project, 'DataR', 'Results', 'Results20220818', 'lags-city-sim.qs')
)
# Clean up
rm(est_lead1, est_lag0, est_lag1, est_lag2, est_lag3)
gc()


# Robustness: Controls ---------------------------------------------------------
# Marginal price
est_mrg = list(
  feols(
    log(thm_day) ~
      1 |
      hh_id + city_ym |
      log(price_mrg_lag2) ~ spot_price_1week_lag2 + spot_price_1week_lag2:utility,
    cluster = ~hh_id + price_cluster,
    data = sub_dt,
    mem.clean = TRUE,
    lean = FALSE
  ),
  feols(
    log(thm_day) ~
      I(bill_hdd/days) |
      hh_id + sw(city_ym, city_ym, city_yw, zip_yw) |
      log(price_mrg_lag2) ~ spot_price_1week_lag2 + spot_price_1week_lag2:utility,
    cluster = ~hh_id + price_cluster,
    data = sub_dt,
    mem.clean = TRUE,
    lean = FALSE
  )
)
qs::qsave(
  x = est_mrg,
  file = file.path(dir_project, 'DataR', 'Results', 'Results20220818', 'rob-mrg.qs')
)
rm(est_mrg); invisible(gc())
# Average price
est_avg = list(
  feols(
    log(thm_day) ~
      1 |
      hh_id + city_ym |
      log(price_avg_lag2) ~ spot_price_1week_lag2 + spot_price_1week_lag2:utility,
    cluster = ~hh_id + price_cluster,
    data = sub_dt,
    mem.clean = TRUE,
    lean = FALSE
  ),
  feols(
    log(thm_day) ~
      I(bill_hdd/days) |
      hh_id + sw(city_ym, city_ym, city_yw, zip_yw) |
      log(price_avg_lag2) ~ spot_price_1week_lag2 + spot_price_1week_lag2:utility,
    cluster = ~hh_id + price_cluster,
    data = sub_dt,
    mem.clean = TRUE,
    lean = FALSE
  )
)
qs::qsave(
  x = est_avg,
  file = file.path(dir_project, 'DataR', 'Results', 'Results20220818', 'rob-avg.qs')
)
rm(est_avg); invisible(gc())
# Baseline price
est_base = list(
  feols(
    log(thm_day) ~
      1 |
      hh_id + city_ym |
      log(price_base_lag2) ~ spot_price_1week_lag2 + spot_price_1week_lag2:utility,
    cluster = ~hh_id + price_cluster,
    data = sub_dt,
    mem.clean = TRUE,
    lean = FALSE
  ),
  feols(
    log(thm_day) ~
      I(bill_hdd/days) |
      hh_id + sw(city_ym, city_ym, city_yw, zip_yw) |
      log(price_base_lag2) ~ spot_price_1week_lag2 + spot_price_1week_lag2:utility,
    cluster = ~hh_id + price_cluster,
    data = sub_dt,
    mem.clean = TRUE,
    lean = FALSE
  )
)
qs::qsave(
  x = est_base,
  file = file.path(dir_project, 'DataR', 'Results', 'Results20220818', 'rob-base.qs')
)
rm(est_base); invisible(gc())
# Average marginal price
est_avg_mrg = list(
  feols(
    log(thm_day) ~
      1 |
      hh_id + city_ym |
      log(price_avg_mrg_lag2) ~ spot_price_1week_lag2 + spot_price_1week_lag2:utility,
    cluster = ~hh_id + price_cluster,
    data = sub_dt,
    mem.clean = TRUE,
    lean = FALSE
  ),
  feols(
    log(thm_day) ~
      I(bill_hdd/days) |
      hh_id + sw(city_ym, city_ym, city_yw, zip_yw) |
      log(price_avg_mrg_lag2) ~ spot_price_1week_lag2 + spot_price_1week_lag2:utility,
    cluster = ~hh_id + price_cluster,
    data = sub_dt,
    mem.clean = TRUE,
    lean = FALSE
  )
)
qs::qsave(
  x = est_avg_mrg,
  file = file.path(dir_project, 'DataR', 'Results', 'Results20220818', 'rob-avg-mrg.qs')
)
rm(est_avg_mrg); invisible(gc())
# Simulated marginal
est_sim = list(
  feols(
    log(thm_day) ~
      1 |
      hh_id + city_ym |
      log(mrg_sim_iv_10_14) ~ spot_price_1week_lag2 + spot_price_1week_lag2:utility,
    cluster = ~hh_id + price_cluster,
    data = sub_dt,
    mem.clean = TRUE,
    lean = FALSE
  ),
  feols(
    log(thm_day) ~
      I(bill_hdd/days) |
      hh_id + sw(city_ym, city_ym, city_yw, zip_yw) |
      log(mrg_sim_iv_10_14) ~ spot_price_1week_lag2 + spot_price_1week_lag2:utility,
    cluster = ~hh_id + price_cluster,
    data = sub_dt,
    mem.clean = TRUE,
    lean = FALSE
  )
)
qs::qsave(
  x = est_sim,
  file = file.path(dir_project, 'DataR', 'Results', 'Results20220818', 'rob-sim.qs')
)
rm(est_sim); invisible(gc())
